<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录与注册</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#3B82F6',
                        secondary: '#10B981',
                    },
                }
            }
        }
    </script>
    <style type="text/tailwindcss">
        @layer utilities {
            .input-focus {
                @apply focus:ring-2 focus:ring-primary/50 focus:border-primary transition duration-200;
            }
            .error {
                @apply text-red-500 text-sm mt-2 mb-4 text-center;
            }
        }
    </style>
</head>
<body class="bg-gray-50 font-sans min-h-screen flex items-center justify-center p-4">
<div class="w-full max-w-md">

        <!-- 检查 error 属性是否存在 -->
        <% if (request.getAttribute("error") != null) { %>
        <p class="error"><%= request.getAttribute("error") %></p>
        <% } %>


    <!-- 表单切换选项卡 -->
    <div class="flex mb-6">
        <button id="login-tab" class="flex-1 py-3 border-b-2 border-primary text-primary font-medium text-lg">
            登录
        </button>
        <button id="register-tab" class="flex-1 py-3 border-b-2 border-transparent text-gray-500 font-medium text-lg">
            注册
        </button>
    </div>

    <!-- 登录表单（新增角色选择） -->
    <form id="login-form" action="login" method="post" class="space-y-6">
        <div>
            <label for="username" class="block text-sm font-medium text-gray-700 mb-1">用户名</label>
            <div class="relative">
                <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                    <i class="fa fa-user text-gray-400"></i>
                </div>
                <input type="text" id="username" name="username" required
                       class="pl-10 w-full rounded-lg border-gray-300 shadow-sm focus:outline-none input-focus py-3 px-4 border"
                       placeholder="请输入用户名">
            </div>
        </div>

        <div>
            <label for="password" class="block text-sm font-medium text-gray-700 mb-1">密码</label>
            <div class="relative">
                <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                    <i class="fa fa-lock text-gray-400"></i>
                </div>
                <input type="password" id="password" name="password" required
                       class="pl-10 w-full rounded-lg border-gray-300 shadow-sm focus:outline-none input-focus py-3 px-4 border"
                       placeholder="请输入密码">
            </div>
        </div>

        <!-- 新增角色选择：管理员/用户 -->
        <div class="flex items-center space-x-4">
            <div>
                <input type="radio" id="role-user" name="role" value="0" checked>
                <label for="role-user" class="text-sm text-gray-700">普通用户</label>
            </div>
            <div>
                <input type="radio" id="role-admin" name="role" value="1">
                <label for="role-admin" class="text-sm text-gray-700">管理员</label>
            </div>
        </div>

        <div>
            <button type="submit" class="w-full bg-primary hover:bg-primary/90 text-white font-medium py-3 px-4 rounded-lg transition duration-200">
                登录
            </button>
        </div>
    </form>

    <!-- 注册表单（新增角色选择，默认普通用户） -->
    <form id="register-form" action="register" method="post" class="space-y-6 hidden">
        <div>
            <label for="reg-username" class="block text-sm font-medium text-gray-700 mb-1">用户名</label>
            <div class="relative">
                <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                    <i class="fa fa-user text-gray-400"></i>
                </div>
                <input type="text" id="reg-username" name="username" required
                       class="pl-10 w-full rounded-lg border-gray-300 shadow-sm focus:outline-none input-focus py-3 px-4 border"
                       placeholder="请输入用户名">
            </div>
        </div>

        <div>
            <label for="phone" class="block text-sm font-medium text-gray-700 mb-1">手机号</label>
            <div class="relative">
                <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                    <i class="fa fa-phone text-gray-400"></i>
                </div>
                <input type="tel" id="phone" name="phone" required
                       class="pl-10 w-full rounded-lg border-gray-300 shadow-sm focus:outline-none input-focus py-3 px-4 border"
                       placeholder="请输入手机号">
            </div>
        </div>

        <div>
            <label for="reg-password" class="block text-sm font-medium text-gray-700 mb-1">密码</label>
            <div class="relative">
                <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                    <i class="fa fa-lock text-gray-400"></i>
                </div>
                <input type="password" id="reg-password" name="password" required
                       class="pl-10 w-full rounded-lg border-gray-300 shadow-sm focus:outline-none input-focus py-3 px-4 border"
                       placeholder="请输入密码">
            </div>
        </div>

        <div>
            <button type="submit" class="w-full bg-secondary hover:bg-secondary/90 text-white font-medium py-3 px-4 rounded-lg transition duration-200">
                注册
            </button>
        </div>
    </form>
</div>

<script>
    // 表单切换逻辑
    function switchTab(activeTab, inactiveTab, activeForm, inactiveForm) {
        activeTab.classList.add('border-primary', 'text-primary');
        activeTab.classList.remove('border-transparent', 'text-gray-500');
        inactiveTab.classList.add('border-transparent', 'text-gray-500');
        inactiveTab.classList.remove('border-primary', 'text-primary');
        activeForm.classList.remove('hidden');
        inactiveForm.classList.add('hidden');
    }

    document.getElementById('login-tab').addEventListener('click', function() {
        switchTab(
            document.getElementById('login-tab'),
            document.getElementById('register-tab'),
            document.getElementById('login-form'),
            document.getElementById('register-form')
        );
    });

    document.getElementById('register-tab').addEventListener('click', function() {
        switchTab(
            document.getElementById('register-tab'),
            document.getElementById('login-tab'),
            document.getElementById('register-form'),
            document.getElementById('login-form')
        );
    });
</script>
</body>
</html>